/**
 * 8. 字符串转换整数 (atoi)
 * @param {string} str
 * @return {number}
 */
var myAtoi = function(str) {
    let result = ''
    if (str.length <= 0) {
        return str
    }
    // 剔除空格
    str = str.replace(/\s+/g,"")
    for (let i of str) {
        let code = i.charCodeAt()
        if ((code == 43 || code == 45 && result.length <= 0) || (code >= 48 && code <= 57)) {
            result+=i
        } else {
            break
        }
    }
    console.log('result', result)
    if (result === '-' || result === '+') {
        result = 0
    }
    result = Number(result)
    result = Math.abs(result) > Math.pow(2, 31) ? result < 0 ? Math.pow(2, 31) * -1 : Math.pow(2, 31) : result
    return Number(result)
};